package com.example.agriculyural.SingletonPattern;
// ================== 单例模式 (Singleton Pattern) ==================

// GPS导航系统（单例）
public class GPSNavigationSystem {
    private static GPSNavigationSystem instance;
    private double latitude;
    private double longitude;

    private GPSNavigationSystem() {
        // 初始化GPS坐标
        this.latitude = 39.9042;
        this.longitude = 116.4074;
    }

    public static synchronized GPSNavigationSystem getInstance() {
        if (instance == null) {
            instance = new GPSNavigationSystem();
            System.out.println("GPS导航系统初始化完成");
        }
        return instance;
    }

    public void updatePosition(double lat, double lon) {
        this.latitude = lat;
        this.longitude = lon;
        System.out.println("GPS位置更新: 纬度=" + latitude + ", 经度=" + longitude);
    }

    public String getCurrentPosition() {
        return "当前位置: 纬度=" + latitude + ", 经度=" + longitude;
    }
}